@extends('layouts.default')
@section('content')
    <div class="row">
        <div class="col-md-12">
            <!-- general form elements -->
            <div class="card card-primary">
                <div class="card-header">
                    @if(!isset($list))
                        <h3 class="card-title">创建酒店</h3>
                    @else
                        <h3 class="card-title">编辑酒店</h3>
                    @endif
                </div>
                @include('layouts.error')
                <form id="validation-form" role="form" method="post" enctype="multipart/form-data" action="{{url('admin/hotel/save')}}">
                    {{ csrf_field() }}
                    <input type="hidden" name="hotel_id" value="{{isset($list)?$list['hotel_id']:''}}">
                    <div class="card-body">
                        <div class="form-group">
                            <label for="banner-title">酒店名称</label>
                            <input type="text" name="name" class="form-control"  placeholder="" value="{{isset($list)?getFieldValue($list,'name'):''}}">
                        </div>
                        <div class="form-group">
                            <label for="banner-title">联系人</label>
                            <input type="text" name="concact_user" class="form-control"  placeholder="" value="{{isset($list)?getFieldValue($list,'concact_user'):''}}">
                        </div>
                        <div class="form-group">
                            <label for="banner-title">手机号</label>
                            <input type="text" name="phone" class="form-control"  placeholder="" value="{{isset($list)?getFieldValue($list,'phone'):''}}">
                        </div>
                        <div class="form-group">
                            <label for="banner-image">具体地址</label><br>
                            <input type="text" name="address" class="form-control"  placeholder="" value="{{isset($list)?getFieldValue($list,'address'):''}}">
                        </div>
                        <div class="form-group">
                            <label for="banner-image">比例分成</label><br>
                            <input type="text" name="divide_rate" class="form-control"  placeholder="" value="{{isset($list)?getFieldValue($list,'divide_rate'):''}}">
                        </div>
                    </div>
                    <!-- /.card-body -->

                    <div class="card-footer" >
                        <button type="submit" class="btn btn-primary " style="float: right">提交</button>
                    </div>
                </form>
            </div>
        </div>
    </div>
@stop
@section('script')
    <script src="{{asset('admin-lte/plugins/jquery-validation/js/jquery.validate.js')}}"></script>
    <script src="{{asset('js/spu/form-validate.js')}}"></script>
    <script>
        var form = {
            init : function(){
              this.validationInit();
            },
            //jqvalidation验证字段有效性
            validationInit:function(){
                var form1 = $('#validation-form');
                var that = this;
                form1.validate({
                    focusInvalid: false, // do not focus the last invalid input
                    ignore: ".edui-container input,.file-caption-name,.btn_batch_set,.pull-none,:checkbox",  // validate all fields including form hidden input
                    messages: {
                        'name':{'required':'酒店名称必填'},
                        'concact_user':{'required':'联系人必填'},
                        'phone':{'required':'手机号必填'},
                        'address':{'required':'地址不能为空'},
                        'divide_rate':{'required':"分成比例必填",range:'分成比例必须是0-1之间的数字'},
                    },
                    rules: {
                        'name':{'required':true},
                        'concact_user':{'required':true},
                        'phone':{'required':true},
                        'address':{'required':true},
                        'divide_rate':{'required':true,range:[0,1]},
                    }
                });
            }
        }
        form.init();
    </script>
@stop